package com.example.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mapper.HotelMapper;
import com.example.pojo.Hotel;
import com.example.service.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class HotelServiceImpl  implements HotelService {//extends ServiceImpl<HotelMapper,Hotel>
    @Autowired
    private HotelMapper hotelMapper;

    /*
       查询全部房间信息
        */
    @Override
    public List<Hotel> select() {
        List<Hotel> hotel = hotelMapper.select();
     ///   List<Hotel> hotel=hotelMapper.selectList(null);
     //   List<Hotel> hotel1=new Hotel();
        for(Hotel h:hotel){
          //  List<Hotel> hotel1=new Hotel(h);
//            hotel1.setId(h.getId());
//            hotel1.setName(h.getName());
//            hotel1.setPrice(h.getPrice());
//            hotel1.setNumber(hotel1.getNumber());
        }
        return hotel;
    }

    /*
    查询可预订的房间信息
     */
    @Override
    public List<Hotel> list() {
   //     QueryWrapper<Hotel> queryWrapper = new QueryWrapper<>();
   //     queryWrapper.gt("number",0);
    //    List<Hotel> hotels = hotelMapper.selectList(queryWrapper);
        List<Hotel> hotels = hotelMapper.list();
       return hotels;
    }

    /*
   预定酒店房间  根据传进来的id预订房间  路径参数  修改房间数量  没有返回值，只有查询才有返回值
    */
    @Override
    public void update(int id,int num) {//不用处理什么逻辑，只需要帮Controller传递参数即可，而且没有返回值
        hotelMapper.update(id,num);
/*        UpdateWrapper<Hotel> updateWrapper = new UpdateWrapper<>();
       updateWrapper.eq("id",id).ge("number",num);
       updateWrapper.set("number","number-="+num);
        hotelMapper.update(null,updateWrapper);*/
    }

    /*
    添加酒店房间
     */
    @Override
    public void add(Hotel hotel) {
 //       hotelMapper.insert(hotel);
       hotelMapper.add(hotel);
    }

    /*
    根据id删除酒店房间
     */
    @Override
    public void delete(int id) {
  //      hotelMapper.deleteById(id);
        hotelMapper.delete(id);
    }
}
